---
category: String
created: '2020-05-15'
title: Convert a Windows file path to Unix path
updated: '2021-10-13'
---

**JavaScript version**

```js toUnixPath.js
const toUnixPath = (path) => path.replace(/[\\/]+/g, '/').replace(/^([a-zA-Z]+:|\.\/)/, '');
```

**TypeScript version**

```ts toUnixPath.ts
const toUnixPath = (path: string): string => path.replace(/[\\/]+/g, '/').replace(/^([a-zA-Z]+:|\.\/)/, '');
```

**Examples**

```js examples.js
toUnixPath('./foo/bar/baz'); // foo/bar/baz
toUnixPath('C:\\foo\\bar\\baz'); // /foo/bar/baz
```
